from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import sys
sys.path.append(r'..')
from web_case.base_page import BasePage
class BaiduPage(BasePage):
    url=r'https://www.baidu.com/'
    '''搜索定位'''
    kw_loc=(By.ID,'kw')
    su_loc=(By.ID,'su')
    
#     登录定位
    lgoin_btn_loc=(By.XPATH,'//*[@id="s-top-loginbtn"]')
    username_loc=(By.ID,'TANGRAM__PSP_11__userName')
    password_loc=(By.ID,'TANGRAM__PSP_11__password')
    isagree_loc=(By.ID,'TANGRAM__PSP_11__isAgree')
    login_submit_loc=(By.ID,'TANGRAM__PSP_11__submit')

    def __init__(self,driver):
        super().__init__(driver)
        self.get_url(self.url)

    # 搜索
    def search(self,kw):
        self.ele_clear(self.kw_loc)
        self.input_ele(self.kw_loc,kw)
        self.ele_click(self.su_loc)
        sleep(3)
    # 登录
    def login(self,username,password):
        self.ele_click(self.lgoin_btn_loc)
        sleep(3)
        self.ele_clear(self.username_loc)
        self.input_ele(self.username_loc,username)
        self.ele_clear(self.password_loc)
        self.input_ele(self.password_loc,password)
        self.ele_click(self.isagree_loc)
        self.ele_click(self.login_submit_loc)
        sleep(3)
if __name__ == '__main__':
    kw = 'selenium'
    username = '123'
    password = '456'

    chrome_location =r'D:\Soft\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location

    driver = webdriver.Chrome(options=options)
    baidu_page = BaiduPage(driver)

    # 测试搜索
    baidu_page.search(kw)

    # 测试登录
    baidu_page.login(username, password)

    driver.quit()
